package java5;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Q5_2Comparator {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		PersonSortable2[] arr = new PersonSortable2[n];
		for (int i = 0; i < arr.length; i++) {
			String name = in.next();
			int age = in.nextInt();
			arr[i] = new PersonSortable2(name, age);
		} 
		Arrays.sort(arr, new NameComparator());
		System.out.println("NameComparator:sort");
		for (int i = 0; i < arr.length; i++) {
			System.out.println(arr[i]);
		}
		Arrays.sort(arr, new AgeComparator());
		System.out.println("AgeComparator:sort");
		for (int i = 0; i < arr.length; i++) {
			System.out.println(arr[i]);
		}
		System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
		System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
	}

}

class NameComparator implements Comparator<PersonSortable2> {
	public int compare(PersonSortable2 other1, PersonSortable2 other2) {
		return other1.getName().compareTo(other2.getName());
	}
}

class AgeComparator implements Comparator<PersonSortable2> {
	public int compare(PersonSortable2 other1, PersonSortable2 other2) {
		return other1.getAge() - other2.getAge();
	}

}

class PersonSortable2 {
	private String name;
	private int age;

	public PersonSortable2(String name, int age) {
		this.name = name;
		this.age = age;
	}

	@Override
	public String toString() {
		return name + "-" + age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

}
